<?php

namespace App\Repository;
use App\Models\Sales\OrderItems;

/**
 * 订单明细数据仓储类
 *
 * @package App\Http\Repository
 * @author WangBin
 * @mail: <849850352@qq.com>
 */
class OrderItemRepository extends BaseRepository
{
    /**
     * 获取订单明细
     *
     * @param int $orderId
     * @return int|mixed
     */
    public function getByOrderId(int $orderId)
    {
        return OrderItems::query()->where('order_id', $orderId)->get();
    }

    /**
     * 更新订单明细 By Id
     *
     * @param array $data
     * @param int $itemId
     * @return int
     */
    public function update(array $data, int $itemId)
    {
        return OrderItems::query()->where('item_id', $itemId)->update($data);
    }

    /**
     * 根据订单 Id 、商品 Id 查询明细
     *
     * @param int $orderId
     * @param int $productId
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getByOrderAndProduct(int $orderId, int $productId)
    {
        return OrderItems::query()->where('order_id', $orderId)->where('product_id', $productId)->first();
    }
}
